import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import APlayer from '@moefe/vue-aplayer';

import store from './store'
import {getRequest} from './utils/api'
import {postRequest} from './utils/api'
import {postRequests} from './utils/api'
import {deleteRequest} from './utils/api'
import {putRequest} from './utils/api'
import {uploadFileRequest} from './utils/api'
import {initMenu} from './utils/utils'
Vue.config.productionTip = false
Vue.use(ElementUI)

Vue.use(APlayer, {
  defaultCover: 'https://github.com/u3u.png',
  productionTip: true,
});

Vue.prototype.getRequest = getRequest;
Vue.prototype.postRequest = postRequest;
Vue.prototype.deleteRequest = deleteRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.postRequests=postRequests;
Vue.prototype.uploadFileRequest=uploadFileRequest;


router.beforeEach((to, from, next)=> {
    if (to.name == 'Login') {
      next();
      return;
    }
    var name = store.state.users.userName;
    if (name == '未登录') {
      if (to.meta.requireAuth || to.name == null) {
        next({path: '/', query: {redirect: to.path}})
      } else {
        next();
      }
    } else {
      initMenu(router, store);
      next();
    }
  }
)

new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: {App}
})
